package com.jiazhong.shixi.yangtong_bookstore.controller;

import com.jiazhong.shixi.yangtong_bookstore.bean.User;
import com.jiazhong.shixi.yangtong_bookstore.mapper.UserMapper;
import com.jiazhong.shixi.yangtong_bookstore.util.JsonResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserMapper userMapper;
    @RequestMapping("/find")
    public JsonResult find(User user){//参数
        User u  = userMapper.login(user);
        if (u == null){
            //登录失败
            JsonResult result = new JsonResult(false,500,null,"账号或者密码错误");
            return result;
        }else{
            JsonResult result = new JsonResult(true,200,u,"");
            return result;

        }
    }
    @RequestMapping("/add")
    public JsonResult add(User user){
        userMapper.add(user);
        JsonResult result = new JsonResult(true,200,"success","");
        return result;
    }
}
